<template>
  <!--<div class="container">-->
      <!--<div class='login_content'>-->
        <!--<div class='user_photo'><open-data type="userAvatarUrl"></open-data></div>-->
        <!--<div class='user_nickname'><open-data type="userNickName"></open-data></div>-->
        <!--<button  v-if="canIUse" class="login_btn" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">点击授权登录</button>-->
        <!--<div v-else>请升级微信版本</div>-->
      <!--</div>-->
  <!--</div>-->
    <div class="container">
        <div class="img-box">
            <img class="main-img" src="https://file.zliangchina.com/weishang/images/login-back.jpg" alt="beauty"/>
            <!--<img class="main-img" :src="home_img_url" alt="beauty"/>-->
        </div>
        <button  v-if="canIUse" class="main-link" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">请点击申请授权</button>
        <div v-else>请升级微信版本</div>
    </div>
</template>
<script>
export default {
  data () {
    return {
      canIUse: wx.canIUse('button.open-type.getUserInfo'),
      home_img_url:"",
        has_login:0,
    }
  },
  methods: {
  checkStatus(a){
      var userToken=wx.getStorageSync('userToken');
      wx.request({
          url:'https://wz.zliangchina.com/api/auth/checkUser?user_token='+userToken,
          method: "GET",
          header: {
              'content-type': 'application/json'
          },
          success(res){
              if(res.data.level=="success") {
                  if(res.data.data == 1){
                      wx.redirectTo({
                          url:'../list/main'
                      })
                  }else {
                      if(a == 1){
                          var aa = "待管理员审核通过，通过后请再次尝试打开";
                          wx.showToast({
                              title: aa,
                              icon:'none',
                              duration:2000
                          })
                      }
                  }
              }else {
                  wx.showToast({
                      title: res.data.message,
                      icon:'none',
                      duration:2000
                  })
              }
          }
      })
  },
   checkLogin(){
       var userToken=wx.getStorageSync('userToken');
       var userInfo = this.$store.state.theUserInfo;
       console.log(userToken);
       console.log(userInfo);
       if(userToken && userToken != '' && userInfo && userInfo != ""){
          this.checkStatus(0);
       }
   },
  bindGetUserInfo(e){
     var _this = this;
     var code = this.$store.state.code;
     if(_this.has_login == 0){
         wx.getUserInfo({
             success(res){
                 var rawData = res.rawData;
                 var signature = res.signature;
                 var encryptedData = res.encryptedData;
                 var iv = res.iv;
                 _this.$store.dispatch("setTheUserInfo",res.userInfo);
                 wx.request({
                     url:'https://wz.zliangchina.com/api/auth/wxLogin',
                     data:{
                         "code":code,
                         "raw_data":rawData,
                         "signature":signature,
                         "encryptedData":encryptedData,
                         "iv":iv
                     },
                     method: "POST",
                     header: {
                         'content-type': 'application/json'
                     },
                     success(res){
                         if(res.data.level=="success") {
                             wx.setStorageSync('userToken', res.data.data);
                             _this.has_login = 1;
                             _this.checkStatus(1);
                         }else {
                             wx.showToast({
                                 title: res.data.message,
                                 icon:'none',
                                 duration:2000
                             })
                         }
                     }
                 })
             }
         })
     }else {
         _this.checkStatus(1);
     }

  },
      // getHomeImg () {
      //     var _this = this;
      //     console.log("bbb"+this.$store.state.theUserInfo);
      //     // 调用接口
      //     wx.request({   //获取用户打卡信息列表
      //         url: 'https://wz.zliangchina.com/api/product/get-home-img',
      //         method:"GET",
      //         header: {
      //             'content-type': 'application/json' // 默认值
      //         },
      //         success: function(res) {
      //             if(res.data.level == "success"){
      //                 _this.home_img_url = res.data.data;
      //             }
      //         }
      //     })
      //
      // },
  },
     onLoad () {
         // this.getHomeImg(),
              this.checkLogin()
     }
}
</script>
<style scoped>
/*.login_content{width: 100%;position: absolute;left: 0;top: 20%;}*/
/*.user_photo{width: 200px;margin:0 auto;}*/
/*.user_nickname{text-align: center;margin-top: 20px}*/
/*button{margin-top: 30px;border-radius:2px;width: 68%;margin-left: 15%;border: solid 1px green;background-color: white;color: green}*/
/*@keyframes zoomInOut*/
/*{*/
    /*from {transform: scale(1, 1);}*/
    /*to {transform: scale(1.25, 1.25);}*/
/*}*/
.container {
    width: 100%;
    height: 100vh;
    background: #f5f5f5;
}
.img-box {
    height: 100%;
    width: 100%;
}
.main-img {
    min-width: 100%;
    min-height: 100%;
    /*animation: zoomInOut 15s linear infinite alternate;*/
}
.main-link {
    position: absolute;
    top: 54%;
    /*left: 0;*/
    right:120rpx;
    margin: auto;
    width: 38%;
    line-height: 72rpx;
    /*border: none;*/
    color: #fff;
    font-size: 33rpx;
    text-align: center;
    /*background: rgba(0,0,0,0.7);*/
    /*border-radius: 5px;*/
    background: none !important;
    color: #000 !important;
    border-bottom:1.5px solid #000;
    font-weight: bold;
}
.main-link::after{
  border: none;
}
</style>
